package at.fhj.itm10.ticketmaster.validators;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 * PasswordValidator.
 * 
 * @author Sabrina Gruber
 * @author Tammo Boehme
 */

@FacesValidator(value = "PasswordValidator")
public class PasswordValidator implements Validator {

	public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        UIInput passwordComponent = (UIInput) component.getAttributes().get("passwordComponent");
        String password = (String) passwordComponent.getValue();
        String confirmPassword = (String) value;

        if (confirmPassword != null && !confirmPassword.equals(password)) {
            throw new ValidatorException(new FacesMessage(
                "Diese Passwörter stimmen nicht überein."));
        }
    }

}
